
namespace Behemoth.SharePoint.Data {

    using System;
    using System.ComponentModel;
    using System.Collections.Generic;
    using System.Text;

    using System.Web.UI.WebControls;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.WebControls;

    using System.Xml.Serialization;

	[Serializable()]
	[XmlRoot( ElementName = "DataSourceProperties", IsNullable = false, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	[XmlType( TypeName = "DataSourceControlProperties", IncludeInSchema = true, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	public partial class DataSourceControlProperties {

		private Guid id;
		/// <summary>
		/// A unique key for this data source description in the form of a Guid.
		/// </summary>
		[XmlAttribute( AttributeName = "ID" )]
		[DefaultValue( typeof( string ), "" )]
		public string ID {
			get { return id.ToString(); }
			set { id = new Guid(value); }
		}
		public Guid ID_Guid {
			get { return id; }
		}

		private string name;
		/// <summary>
		/// A unique name for this data source. This will be made part of the
		/// control's ID property.
		/// </summary>
		[XmlAttribute( AttributeName = "Name" )]
		[DefaultValue( typeof( string ), "" )]
		public string Name {
			get { return name; }
			set { name = value; }
		}

		private string assemblyName;
		/// <summary>
		/// The long name of the assembly that contrains the desired data source control.
		/// </summary>
		[XmlAttribute( AttributeName = "AssemblyName" )]
		[DefaultValue( typeof( string ), "" )]
		public string AssemblyName {
			get { return assemblyName; }
			set { assemblyName = value; }
		}

		private string typeName;
		/// <summary>
		/// The type name that will be used to generate the control instance.
		/// The type specified must inherit from System.Web.UI.DataSourceControl.
		/// </summary>
		[XmlAttribute( AttributeName = "TypeName" )]
		[DefaultValue( typeof( string ), "" )]
		public string TypeName {
			get { return typeName; }
			set { typeName = value; }
		}

		private string connectionString;
		/// <summary>
		/// 
		/// </summary>
		/// <remarks>populates DataFile for XML</remarks>
		[XmlElement( ElementName = "AssemblyName", IsNullable = false )]
		[DefaultValue( typeof( string ), "" )]
		public string ConnectionString {
			get { return connectionString; }
			set { connectionString = value; }
		}

		private bool cancelSelectOnNullParameter;
		[XmlElement( ElementName = "CancelSelectOnNullParameter", IsNullable = false )]
		[DefaultValue( typeof( bool ), "false" )]
		public bool CancelSelectOnNullParameter {
			get { return cancelSelectOnNullParameter; }
			set { cancelSelectOnNullParameter = value; }
		}

		private AuthenticationProperties authentication;
		/// <summary>
		/// Consumers of this class do not need to set this property directly as it will be instantiated upon first get
		/// </summary>
		[XmlElement( ElementName = "Authentication", Type = typeof( AuthenticationProperties ) )] // 
		public AuthenticationProperties Authentication {
			get {
				//if (authentication == null)
				//	authentication = new AuthenticationProperties();
				return authentication;
			}
			set { authentication = value; }
		}

		private SqlDataSourceProperties sqlProperties;
		/// <summary>
		/// Consumers of this class do not need to set this property directly as it will be instantiated upon first get
		/// </summary>
		[XmlElement( ElementName = "SqlProperties", Type = typeof( SqlDataSourceProperties ) )] // 
		public SqlDataSourceProperties SqlProperties {
			get {
				//if (sqlProperties == null)
				//	sqlProperties = new SqlDataSourceProperties();
				return sqlProperties;
			}
			set { sqlProperties = value; }
		}

		private XmlDataSourceProperties xmlProperties;
		/// <summary>
		/// Consumers of this class do not need to set this property directly as it will be instantiated upon first get
		/// </summary>
		[XmlElement( ElementName = "XmlProperties", Type = typeof( XmlDataSourceProperties ) )] // 
		public XmlDataSourceProperties XmlProperties {
			get {
				//if (xmlProperties == null)
				//	xmlProperties = new XmlDataSourceProperties();
				return xmlProperties;
			}
			set { xmlProperties = value; }
		}

		private WebDataSourceProperties webProperties;
		/// <summary>
		/// Consumers of this class do not need to set this property directly as it will be instantiated upon first get
		/// </summary>
		[XmlElement( ElementName = "WebProperties", Type = typeof( WebDataSourceProperties ) )] // 
		public WebDataSourceProperties WebProperties {
			get {
				//if (webProperties == null)
				//	webProperties = new WebDataSourceProperties();
				return webProperties;
			}
			set { webProperties = value; }
		}

		private SpDataSourceProperties sharePointProperties;
		/// <summary>
		/// Consumers of this class do not need to set this property directly as it will be instantiated upon first get
		/// </summary>
		[XmlElement( ElementName = "SharePointProperties", Type = typeof( SpDataSourceProperties ) )] // 
		public SpDataSourceProperties SharePointProperties {
			get {
				//if (sharePointProperties == null)
				//	sharePointProperties = new SpDataSourceProperties();
				return sharePointProperties;
			}
			set { sharePointProperties = value; }
		}

		private string selectCommand;
		/// <summary>
		/// 
		/// </summary>
		/// <remarks>populates XPath for XML and XmlUrl</remarks>
		[XmlElement( ElementName = "SelectCommand", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string SelectCommand {
			get { return selectCommand; }
			set { selectCommand = value; }
		}

		private ParameterCollection selectParameters;
		/// <summary>
		/// 
		/// </summary>
		/// <remarks>populates DataFileParameters for XML</remarks>
		[XmlElement( ElementName = "SelectParameters", Type = typeof( ParameterCollection ) )] // DataType = "Parameter",
		public ParameterCollection SelectParameters {
			get {
				if (selectParameters == null)
					selectParameters = new ParameterCollection();
				return selectParameters;
			}
		}

		private string insertCommand;
		[XmlElement( ElementName = "InsertCommand", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string InsertCommand {
			get { return insertCommand; }
			set { insertCommand = value; }
		}

		private ParameterCollection insertParameters;
		[XmlElement( ElementName = "InsertParameters", Type = typeof( ParameterCollection ) )] // DataType = "Parameter",
		public ParameterCollection InsertParameters {
			get {
				if (insertParameters == null)
					insertParameters = new ParameterCollection();
				return insertParameters;
			}
		}

		private string updateCommand;
		[XmlElement( ElementName = "UpdateCommand", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string UpdateCommand {
			get { return updateCommand; }
			set { updateCommand = value; }
		}

		private ParameterCollection updateParameters;
		[XmlElement( ElementName = "UpdateParameters", Type = typeof( ParameterCollection ) )] // DataType = "Parameter",
		public ParameterCollection UpdateParameters {
			get {
				if (updateParameters == null)
					updateParameters = new ParameterCollection();
				return updateParameters;
			}
		}

		private string deleteCommand;
		[XmlElement( ElementName = "DeleteCommand", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string DeleteCommand {
			get { return deleteCommand; }
			set { deleteCommand = value; }
		}

		private ParameterCollection deleteParameters;
		[XmlElement( ElementName = "DeleteParameters", Type = typeof( ParameterCollection ) )] // DataType = "Parameter",
		public ParameterCollection DeleteParameters {
			get {
				if (deleteParameters == null)
					deleteParameters = new ParameterCollection();
				return deleteParameters;
			}
		}

	}

	[Serializable()]
	[XmlRoot( ElementName = "AuthenticationProperties", IsNullable = false, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	[XmlType( TypeName = "AuthenticationProperties", IncludeInSchema = true, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	public class AuthenticationProperties {

		// for sql
		private bool allowIntegratedSecurity;
		[XmlElement( ElementName = "AllowIntegratedSecurity", IsNullable = false )]
		[DefaultValue( typeof( bool ), "true" )]
		public bool AllowIntegratedSecurity {
			get { return allowIntegratedSecurity; }
			set { allowIntegratedSecurity = value; }
		}

		private string authType;
		[XmlElement( ElementName = "AuthType", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string AuthType {
			get { return authType; }
			set { authType = value; }
		}

		private string authUserName;
		[XmlElement( ElementName = "AuthUserName", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string AuthUserName {
			get { return authUserName; }
			set { authUserName = value; }
		}

		// TBD not very secure :-S
		private string authPassword;
		[XmlElement( ElementName = "AuthPassword", IsNullable=true )]
		[DefaultValue( typeof( string ), "" )]
		public string AuthPassword {
			get { return authPassword; }
			set { authPassword = value; }
		}
	}

	[Serializable()]
	[XmlRoot( ElementName = "SqlDataSourceProperties", IsNullable = false, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	[XmlType( TypeName = "SqlDataSourceProperties", IncludeInSchema = true, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	public class SqlDataSourceProperties {
		
		private SqlDataSourceMode dataSourceMode;
		[XmlElement( ElementName = "DataSourceMode", IsNullable = false )] // , Type = typeof( SqlDataSourceMode ) , DataType = "string"
		[DefaultValue( typeof( SqlDataSourceMode ), "DataSet" )]
		public SqlDataSourceMode DataSourceMode {
			get { return dataSourceMode; }
			set { dataSourceMode = value; }
		}

		private string providerName;
		[XmlElement( ElementName = "ProviderName", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string ProviderName {
			get { return providerName; }
			set { providerName = value; }
		}

		private SqlDataSourceCommandType selectCommandType;
		[XmlElement( ElementName = "SelectCommandType", IsNullable = false )] // , Type = typeof( SqlDataSourceCommandType ), DataType = "string"
		[DefaultValue( typeof( SqlDataSourceCommandType ), "Text" )]
		public SqlDataSourceCommandType SelectCommandType {
			get { return selectCommandType; }
			set { selectCommandType = value; }
		}

		private SqlDataSourceCommandType insertCommandType;
		[XmlElement( ElementName = "InsertCommandType", IsNullable = false )] // , Type = typeof( SqlDataSourceCommandType ), DataType = "string"
		[DefaultValue( typeof( SqlDataSourceCommandType ), "Text" )]
		public SqlDataSourceCommandType InsertCommandType {
			get { return insertCommandType; }
			set { insertCommandType = value; }
		}

		private SqlDataSourceCommandType updateCommandType;
		[XmlElement( ElementName = "UpdateCommandType", IsNullable = false )] // , Type = typeof( SqlDataSourceCommandType ), DataType = "string"
		[DefaultValue( typeof( SqlDataSourceCommandType ), "Text" )]
		public SqlDataSourceCommandType UpdateCommandType {
			get { return updateCommandType; }
			set { updateCommandType = value; }
		}

		private SqlDataSourceCommandType deleteCommandType;
		[XmlElement( ElementName = "DeleteCommandType", IsNullable = false )] // , Type = typeof( SqlDataSourceCommandType ), DataType = "string"
		[DefaultValue( typeof( SqlDataSourceCommandType ), "Text" )]
		public SqlDataSourceCommandType DeleteCommandType {
			get { return deleteCommandType; }
			set { deleteCommandType = value; }
		}

		private string sortParameterName;
		[XmlElement( ElementName = "SortParameterName", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string SortParameterName {
			get { return sortParameterName; }
			set { sortParameterName = value; }
		}

		private string filterExpression;
		[XmlElement( ElementName = "FilterExpression", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string FilterExpression {
			get { return filterExpression; }
			set { filterExpression = value; }
		}

		private ParameterCollection filterParameters;
		[XmlElement( ElementName = "FilterParameters", Type = typeof( ParameterCollection ) )] // , DataType = "string"
		public ParameterCollection FilterParameters {
			get {
				if (filterParameters == null)
					filterParameters = new ParameterCollection();
				return filterParameters;
			}
		}

	}

	/// <summary>
	/// Defines properties that only apply to Xml and XmlUrl data sources
	/// </summary>
	[Serializable()]
	[XmlRoot( ElementName = "XmlDataSourceProperties", IsNullable = false, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	[XmlType( TypeName = "XmlDataSourceProperties", IncludeInSchema = true, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	public class XmlDataSourceProperties {

		private string data;
		[XmlElement( ElementName = "Data", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string Data {
			get { return data; }
			set { data = value; }
		}

		private string transform;
		[XmlElement( ElementName = "Transform", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string Transform {
			get { return transform; }
			set { transform = value; }
		}

		private string dataFile;
		[XmlElement( ElementName = "DataFile", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string DataFile {
			get { return dataFile; }
			set { dataFile = value; }
		}

		private string transformFile;
		[XmlElement( ElementName = "TransformFile", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string TransformFile {
			get { return transformFile; }
			set { transformFile = value; }
		}

		private string xpath;
		[XmlElement( ElementName = "XPath", IsNullable = true )]
		[DefaultValue( typeof( string ), "" )]
		public string XPath {
			get { return xpath; }
			set { xpath = value; }
		}

	} // class

	/// <summary>
	/// Defines properties that only apply to web based data sources
	/// </summary>
	[Serializable()]
	[XmlRoot( ElementName = "WebDataSourceProperties", IsNullable = false, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	[XmlType( TypeName = "WebDataSourceProperties", IncludeInSchema = true, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	public class WebDataSourceProperties {
		// GET or POST
		private string httpMethod;
		[XmlAttribute( AttributeName = "HttpMethod" )]
		[DefaultValue( typeof( string ), "GET" )]
		public string HttpMethod {
			get { return httpMethod; }
			set { httpMethod = value; }
		}
	}

	[Serializable()]
	[XmlRoot( ElementName = "SpDataSourceProperties", IsNullable = false, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	[XmlType( TypeName = "SpDataSourceProperties", IncludeInSchema = true, Namespace = "http://Behemoth.com/Schemas/SharePoint/Data/Dsp" )]
	public class SpDataSourceProperties {

		private SPDataSourceMode dataSourceMode;
		[XmlAttribute( AttributeName = "DataSourceMode" )] // , Type = typeof( SPDataSourceMode )
		[DefaultValue( typeof( SPDataSourceMode ), "List" )]
		public SPDataSourceMode DataSourceMode {
			get { return dataSourceMode; }
			set { dataSourceMode = value; }
		}

		private SPViewScope scope;
		[XmlAttribute( AttributeName = "Scope" )] // , Type = typeof( SPViewScope )
		[DefaultValue( typeof( SPViewScope ), "Default" )]
		public SPViewScope Scope {
			get { return scope; }
			set { scope = value; }
		}

		private bool includeHidden;
		[XmlAttribute( AttributeName = "IncludeHidden" )]
		[DefaultValue( typeof( bool ), "false" )]
		public bool IncludeHidden {
			get { return includeHidden; }
			set { includeHidden = value; }
		}

		private bool useInternalName;
		[XmlAttribute( AttributeName = "UseInternalName" )]
		[DefaultValue( typeof( bool ), "false" )]
		public bool UseInternalName {
			get { return useInternalName; }
			set { useInternalName = value; }
		}

		/*
		private string webUrl;
		[XmlAttribute( AttributeName = "WebUrl" )]
		[DefaultValue( typeof( string ), "" )]
		public string WebUrl {
			get { return webUrl; }
			set { webUrl = value; }
		} 

		private string listNameOrId;
		[XmlAttribute( AttributeName = "ListNameOrId" )]
		[DefaultValue( typeof( string ), "" )]
		public string ListNameOrId {
			get { return listNameOrId; }
			set { listNameOrId = value; }
		}
		 */

	}

} // namespace
